<?php

/*
 *    Document   : settings
 *   Created on : Jun 11, 2011, 3:42:23 PM
 *    Author     : ClarkT AKA FalleN
 *    Company    : Amodity
 *    Web        : http://www.amodity.com
 *    Copyright  : 2011
 */

class settings extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('auth');
        $this->load->model('admin/core');
        $this->core->_prev_url();
        $this->load->helper('config_file');
    }

    public function index() {
        //is user logged in
        $this->core->_is_logged_in();

        if ($this->input->post('site')) {
            if (write_config('config', array(
                        'base_url' => $this->input->post('base_url'),
                        'index_page' => $this->input->post('index'),
                        'theme' => $this->input->post('theme')
                    ))) {
                $this->message->set('success', lang('admin_settings_saved'));
            } else {
                $this->message->set('error', lang('admin_settings_error'));
            }
        } elseif ($this->input->post('local')) {
            if (write_config('config', array(
                        'language' => $this->input->post('base_url'),
                        'charset' => $this->input->post('index')
                    ))) {
                $this->message->set('success', lang('admin_settings_saved'));
            } else {
                $this->message->set('error', lang('admin_settings_error'));
            }
        } elseif ($this->input->post('upload')) {

            if (write_config('upload', array(
                        'upload_path' => $this->input->post('upload_path'),
                        'allowed_types' => $this->input->post('allowed_type'),
                        'max_height' => $this->input->post('max_height'),
                        'max_width' => $this->input->post('max_width'),
                        'max_size' => $this->input->post('max_size'),
                        'max_filename' => $this->input->post('max_filename'),
                        'encrypt_names' => $this->input->post('encrypt_names')
                    ))) {
                $this->message->set('success', lang('admin_settings_saved'));
            } else {
                $this->message->set('error', lang('admin_settings_error'));
            }
        }

        $this->template->set('title', lang('admin_system_settings'));
        $this->template->set('page_title', lang('admin_system_settings'));
        $this->template->load('templates/admin_template', 'system_settings', null, 'admin');
    }

}

/* End of file settings */